﻿using System;
using System.Buffers;
using System.Runtime.InteropServices;
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.Advanced;
using SixLabors.ImageSharp.PixelFormats;
using TiffLibrary.PixelFormats;

namespace DeepZoomRipperLibrary
{
    internal class ImageSharpToTiffLibraryAdapterMemoryManager<TPixelFrom, TPixelTo> : MemoryManager<TPixelTo>
        where TPixelFrom : struct, IPixel<TPixelFrom>
        where TPixelTo : struct, ITiffPixel<TPixelTo>
    {
        private readonly Image<TPixelFrom> _image;

        public ImageSharpToTiffLibraryAdapterMemoryManager(Image<TPixelFrom> image)
        {
            _image = image;
        }

        public override Span<TPixelTo> GetSpan()
        {
            return MemoryMarshal.Cast<TPixelFrom, TPixelTo>(_image.GetPixelSpan());
        }

        public override MemoryHandle Pin(int elementIndex = 0)
        {
            throw new NotSupportedException();
        }

        public override void Unpin()
        {
            throw new NotSupportedException();
        }

        protected override void Dispose(bool disposing)
        {
        }
    }
}
